package com.power.sifa.statistics.dao;

import com.power.sifa.statistics.model.Apl_note_book;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;
import javax.transaction.Transactional;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 * 每日记录记事本 持久层(hibernate)
 */

public interface Apl_note_bookDao extends JpaRepository<Apl_note_book, Serializable>, JpaSpecificationExecutor<Apl_note_book>, Repository<Apl_note_book, Serializable>, Apl_note_bookDaoCustom<Apl_note_book, Serializable> {

   @Modifying
   @Transactional
   @Query("delete  from Apl_note_book s where  s.id in (:ids) ")
   void removeByIds(@Param("ids") List<Integer> ids);


   /**
    * 查询当前用户全部已经填写过的日期
    * @param userid
    * @return
    */
   @Query(value = "select notetime from Apl_note_book s where s.userid = :userid group by notetime  ",
           nativeQuery = true)
   Set<Date> allRecordTime(String userid);


   /**
    * 查询当前用户全部已经填写过的日期
    * @param userid
    * @return
    */
   @Query(value = "select max(sort) from Apl_note_book s where s.userid = :userid and notetime = :notetime  ",
           nativeQuery = true)
   Integer getMaxSortNum (String userid, Date notetime);
}
